package ast.exp;

import icg.EQLabel;
import icg.EQLiteral;
import icg.Quadruple;
import ast.Node;
import ast.type.Type;

public class LitBoolExp extends Expression {
	private Boolean value;

	public LitBoolExp(Boolean value) {
		this.value = value;
		this.type = Type.BOOLEAN;
	}

	@Override
	public Type typeCheck() {
		return type;
	}

	@Override
	public String toString() {
		return "<LitBoolExp value=\"" + value + "\" />";
	}

	@Override
	public void genCode() {
		//this.addr = new EQTemp();
		if (value) {
			this.addr = new EQLiteral("1");
			if (!this.trueL.equals(EQLabel.FALL))
				Node.icg.gen(Quadruple.jump(this.trueL));
			//Node.icg.gen(Quadruple.copy(this.addr, new EQLiteral("1")));
			//this.addr = new EQLiteral("1");
		} else {
			this.addr = new EQLiteral("0");
			if (!this.falseL.equals(EQLabel.FALL))
				Node.icg.gen(Quadruple.jump(this.falseL));
			//Node.icg.gen(Quadruple.copy(this.addr, new EQLiteral("0")));
			//this.addr = new EQLiteral("0");
		}
	}
}
